package com.vitabuybuy.tv.ui.tencent.chat

import android.os.Bundle
import android.view.View
import androidx.core.os.bundleOf
import com.library.common.base.BaseActivity
import com.tencent.qcloud.tim.uikit.modules.chat.base.ChatInfo
import com.tencent.qcloud.tim.uikit.modules.chat.layout.inputmore.InputMoreActionUnit
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ActivityChatBinding

class ChatActivity : BaseActivity<ChatViewModel, ActivityChatBinding>() {

    override val isUseBaseTitleBar: Boolean
        get() = true
    override val layoutId: Int
        get() = R.layout.activity_chat
    var chatInfo: ChatInfo? = null

    override fun onGetBundle(bundle: Bundle?) {
        chatInfo = bundle?.getSerializable("chatInfo") as ChatInfo
    }

    override fun initView(savedInstanceState: Bundle?) {
        initChat()
        initConfig()
    }

    private fun initChat() {
        mBinding.chatLayout.initDefault()
        chatInfo?.run {
            setTitle(chatName)
//            type = TIMConversationType.C2C
//            id = "83"
//            chatName = "马来西亚"
            mBinding.chatLayout.setChatInfo(chatInfo)
        }
    }

    private fun initConfig() {
        //zxy 标题区
        val titleBar = mBinding.chatLayout.titleBar
        titleBar.visibility = View.GONE
//        titleBar.setRightIcon(R.drawable.ic_camera)
//        titleBar.setLeftIcon(R.drawable.ic_back)
        //zxy 内容消息区
        val messageLayout = mBinding.chatLayout.messageLayout
        //设置聊天背景
//        messageLayout.setBackground(new ColorDrawable(0xB0AA6D96));
        // 设置默认头像，默认与朋友与自己的头像相同
        messageLayout.avatar = R.drawable.wode_icon_touxiang;
        // 设置头像圆角，不设置则默认不做圆角处理
        messageLayout.avatarRadius = 55
        // 头像，mIconUrl 就是您上传头像后的 URL，可以参考 Demo 中的随机头像作为示例
//        TIMFriendshipManager.getInstance()
//            .getSelfProfile(object : TIMValueCallBack<TIMUserProfile> {
//                override fun onError(i: Int, s: String) {}
//                override fun onSuccess(timUserProfile: TIMUserProfile) {
//                    setSelfProfile("http://sg.wanjuanlink.com/attachment/jpg/8896/4329_24304.jpg")
////                    setSelfProfile(mmkv.decodeString(MMKVContancts.USER_AVATAR))
////                    setSelfProfile(timUserProfile.faceUrl)
//                }
//            })
        // zxy 输入区域
        // 从 ChatLayout 里获取 InputLayout
        val inputLayout = mBinding.chatLayout.inputLayout
        // 隐藏拍照并发送
        inputLayout.disableCaptureAction(false)
        // 隐藏发送商品
        inputLayout.disableSendFileAction(false)
        // 隐藏发送图片
        inputLayout.disableSendPhotoAction(false)
        // 隐藏摄像并发送
        inputLayout.disableVideoRecordAction(false)
    }

    /**
     * 设置头像
     *
     * @param mIconUrl
     */
//    private fun setSelfProfile(mIconUrl: String) {
//        val hashMap = HashMap<String, Any>()
//        if (!TextUtils.isEmpty(mIconUrl)) {
//            hashMap[TIMUserProfile.TIM_PROFILE_TYPE_KEY_FACEURL] = mIconUrl
//        }
//        TIMFriendshipManager.getInstance().modifySelfProfile(hashMap, object : TIMCallBack {
//            override fun onError(i: Int, s: String) {}
//            override fun onSuccess() {}
//        })
//    }

    companion object {
        fun openActivity(mContext: BaseActivity<*, *>, chatInfo: ChatInfo?) {
            mContext.startActivity(bundleOf(Pair("chatInfo", chatInfo)), ChatActivity::class.java)
        }
    }
}